function New-AzureFirewallRules {
    Param (
        [Parameter(Mandatory = $true)][string][ValidateScript({ !([string]::IsNullOrWhiteSpace($_)) })]$ResourceGroup,
        [Parameter(Mandatory = $true)][string][ValidateScript({ !([string]::IsNullOrWhiteSpace($_)) })]$ServerName,
        [Parameter(Mandatory = $true)][string][ValidateScript({ [IPAddress]::tryparse($_, [ref][IPAddress]::loopback) })]$ClientIPAddress # Validation checks for a valid IP-Address.
    )
    # TODO: Make sure this function works properly...
    <#
        Create firewall rules.
    #>
    
    try {
        # Get all existing firewall rules.
        $params = @{
            ResourceGroupName = $ResourceGroup
            ServerName = $ServerName
        }
        $existingFirewallRules = Get-AzSqlServerFirewallRule @params
    
        # Add firewall rule that allows all azure ip-addresses.
        if ($existingFirewallRules.FirewallRuleName -notcontains 'AllowAllAzureIPs') {
            $params = @{
                ResourceGroupName = $ResourceGroup
                ServerName = $ServerName
                AllowAllAzureIPs = $true
            }
            New-AzSqlServerFirewallRule @params | Out-Null
        }
    
        # Check if the firewall rule exists where the clients ip address is in range.
        $firewallRuleThatAllowsClientIP = $existingFirewallRules | Where-Object { Test-LSIPInRange -FromIPAddress $_.StartIpAddress -ToIPAddress $_.EndIpAddress -IPAddress $ClientIPAddress}
    
        # Add firewall rule that allows client ip-address.
        if (!$firewallRuleThatAllowsClientIP) {
            
            # Generate a new firewall rule name from the existing names.
            $newFirewallRuleName = Get-NewFirewallRuleName -Rules $existingFirewallRules 
            
            # Create a Firewall rule - Open for client IP-address.
            $params = @{
                FirewallRuleName = $newFirewallRuleName
                StartIpAddress = $ClientIPAddress
                EndIpAddress = $ClientIPAddress
                ResourceGroupName = $ResourceGroup
                ServerName = $ServerName
            }
            New-AzSqlServerFirewallRule @params | Out-Null
        }
    }
    catch {
        Write-Warning 'Failed to add firewall rules for the server.'
        Start-Sleep -Milliseconds 100
        Write-Host 'After the install is finished, you must create two new firewall rules on your Azure SQL server:'
        Write-Host '- Allow all Azure IP addresses.'
        Write-Host "- Allow your IP address '" -NoNewline
        Write-Host "$ClientIPAddress" -ForegroundColor 'Red' -NoNewline
        Start-Sleep -Milliseconds 100
        Write-Host "'."
        Read-Host -Prompt 'Ok?' | Out-Null
        # TODO: Create documentation how to add firewall rules...
    }

}